{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Example complicated lactam analysis.\n",
    "\n",
    "The input cores are generic in atoms and bonds, the system figures out the correct cores for grouping purposes.\n",
    "\n",
    "This may be overkill ( and certainly takes a long enough time ).  What the algorithm is doing is first mapping each core to each other and then trying to optimizes the side chain selection across all sets.  I.e. it tries to make the matching choices such that all R1's are the same, all R2's are the same and so on.\n",
    "\n",
    "**n.b.** *It is important that the cores are input in most to least specific as the RGroupDecomposition takes the first matching core.*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/kellebr5/anaconda/lib/python2.7/site-packages/ipykernel/__main__.py:6: RuntimeWarning: to-Python converter for std::vector<boost::shared_ptr<RDKit::ROMol>, std::allocator<boost::shared_ptr<RDKit::ROMol> > > already registered; second conversion method ignored.\n"
     ]
    }
   ],
   "source": [
    "from __future__ import print_function\n",
    "from rdkit import Chem\n",
    "from rdkit.Chem import AllChem\n",
    "from rdkit.Chem.Draw import IPythonConsole\n",
    "IPythonConsole.ipython_useSVG=True\n",
    "from rdkit.Chem.rdRGroupDecomposition import RGroupDecomposition\n",
    "import pandas as pd\n",
    "from rdkit.Chem import PandasTools\n",
    "from collections import OrderedDict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "cores = OrderedDict()\n",
    "\n",
    "cores['six'] = Chem.MolFromSmarts('[#8]-[#6](=O)-*~1~*~*~*~*~2-[#6]-[#6](=O)-*~1~2')\n",
    "cores['five'] = Chem.MolFromSmarts('[#8]-[#6](=O)-*~1~*~*~*~2-[#6]-[#6](=O)-*~1~2')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<svg baseProfile=\"full\" height=\"200px\" version=\"1.1\" width=\"600px\" xml:space=\"preserve\" xmlns:rdkit=\"http://www.rdkit.org/xml\" xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       "<g transform=\"translate(0,0)\"><rect height=\"200\" style=\"opacity:1.0;fill:#FFFFFF;stroke:none\" width=\"200\" x=\"0\" y=\"0\"> </rect>\n",
       "<path d=\"M 28.7654,91.8756 44.2594,99.7627\" style=\"fill:none;fill-rule:evenodd;stroke:#FF0000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 44.2594,99.7627 59.7533,107.65\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 55.5461,107.872 56.4713,125.397\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 56.4713,125.397 57.3964,142.922\" style=\"fill:none;fill-rule:evenodd;stroke:#FF0000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 63.9605,107.428 64.8857,124.953\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 64.8857,124.953 65.8109,142.478\" style=\"fill:none;fill-rule:evenodd;stroke:#FF0000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 59.7533,107.65 75.0725,97.6932\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 75.0725,97.6932 90.3916,87.7365\" style=\"fill:none;fill-rule:evenodd;stroke:#7F7F7F;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 94.7077,77.6685 93.2281,49.6399\" style=\"fill:none;fill-rule:evenodd;stroke:#7F7F7F;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-dasharray:2,6\"/>\n",
       "<path d=\"M 99.7652,87.0761 127.938,101.417\" style=\"fill:none;fill-rule:evenodd;stroke:#7F7F7F;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-dasharray:2,6\"/>\n",
       "<path d=\"M 97.5442,39.5719 123.496,22.7048\" style=\"fill:none;fill-rule:evenodd;stroke:#7F7F7F;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-dasharray:2,6\"/>\n",
       "<path d=\"M 132.869,22.0444 161.042,36.3854\" style=\"fill:none;fill-rule:evenodd;stroke:#7F7F7F;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-dasharray:2,6\"/>\n",
       "<path d=\"M 166.099,45.793 167.579,73.8216\" style=\"fill:none;fill-rule:evenodd;stroke:#7F7F7F;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-dasharray:2,6\"/>\n",
       "<path d=\"M 172.513,87.8652 181.711,102.017\" style=\"fill:none;fill-rule:evenodd;stroke:#7F7F7F;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 181.711,102.017 190.909,116.168\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 163.263,83.8896 137.311,100.757\" style=\"fill:none;fill-rule:evenodd;stroke:#7F7F7F;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-dasharray:2,6\"/>\n",
       "<path d=\"M 190.909,116.168 155.584,139.128\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 151.463,138.254 147.836,155.349\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 147.836,155.349 144.209,172.445\" style=\"fill:none;fill-rule:evenodd;stroke:#FF0000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 159.705,140.002 156.078,157.098\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 156.078,157.098 152.451,174.194\" style=\"fill:none;fill-rule:evenodd;stroke:#FF0000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 155.584,139.128 146.386,124.976\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 146.386,124.976 137.188,110.825\" style=\"fill:none;fill-rule:evenodd;stroke:#7F7F7F;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<text style=\"font-size:14px;font-style:normal;font-weight:normal;fill-opacity:1;stroke:none;font-family:sans-serif;text-anchor:start;fill:#FF0000\" x=\"15.6491\" y=\"95.559\"><tspan>O</tspan></text>\n",
       "<text style=\"font-size:14px;font-style:normal;font-weight:normal;fill-opacity:1;stroke:none;font-family:sans-serif;text-anchor:start;fill:#FF0000\" x=\"55.4162\" y=\"156.744\"><tspan>O</tspan></text>\n",
       "<text style=\"font-size:14px;font-style:normal;font-weight:normal;fill-opacity:1;stroke:none;font-family:sans-serif;text-anchor:start;fill:#7F7F7F\" x=\"90.3916\" y=\"91.7121\"><tspan>?</tspan></text>\n",
       "<text style=\"font-size:14px;font-style:normal;font-weight:normal;fill-opacity:1;stroke:none;font-family:sans-serif;text-anchor:start;fill:#7F7F7F\" x=\"88.1706\" y=\"49.6399\"><tspan>?</tspan></text>\n",
       "<text style=\"font-size:14px;font-style:normal;font-weight:normal;fill-opacity:1;stroke:none;font-family:sans-serif;text-anchor:start;fill:#7F7F7F\" x=\"123.496\" y=\"26.6804\"><tspan>?</tspan></text>\n",
       "<text style=\"font-size:14px;font-style:normal;font-weight:normal;fill-opacity:1;stroke:none;font-family:sans-serif;text-anchor:start;fill:#7F7F7F\" x=\"161.042\" y=\"45.793\"><tspan>?</tspan></text>\n",
       "<text style=\"font-size:14px;font-style:normal;font-weight:normal;fill-opacity:1;stroke:none;font-family:sans-serif;text-anchor:start;fill:#7F7F7F\" x=\"163.263\" y=\"87.8652\"><tspan>?</tspan></text>\n",
       "<text style=\"font-size:14px;font-style:normal;font-weight:normal;fill-opacity:1;stroke:none;font-family:sans-serif;text-anchor:start;fill:#FF0000\" x=\"140.282\" y=\"187.363\"><tspan>O</tspan></text>\n",
       "<text style=\"font-size:14px;font-style:normal;font-weight:normal;fill-opacity:1;stroke:none;font-family:sans-serif;text-anchor:start;fill:#7F7F7F\" x=\"127.938\" y=\"110.825\"><tspan>?</tspan></text>\n",
       "</g>\n",
       "<g transform=\"translate(200,0)\"><rect height=\"200\" style=\"opacity:1.0;fill:#FFFFFF;stroke:none\" width=\"200\" x=\"0\" y=\"0\"> </rect>\n",
       "<path d=\"M 134.827,149.615 137.171,132.498\" style=\"fill:none;fill-rule:evenodd;stroke:#FF0000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 137.171,132.498 139.515,115.382\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 141.085,119.228 157.082,112.699\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 157.082,112.699 173.08,106.169\" style=\"fill:none;fill-rule:evenodd;stroke:#FF0000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 137.945,111.535 153.943,105.006\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 153.943,105.006 169.94,98.4773\" style=\"fill:none;fill-rule:evenodd;stroke:#FF0000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 139.515,115.382 125.413,104.444\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 125.413,104.444 111.311,93.5061\" style=\"fill:none;fill-rule:evenodd;stroke:#7F7F7F;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 106.908,82.9982 107.776,55.3245\" style=\"fill:none;fill-rule:evenodd;stroke:#7F7F7F;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-dasharray:2,6\"/>\n",
       "<path d=\"M 102.069,91.2645 71.4201,100.17\" style=\"fill:none;fill-rule:evenodd;stroke:#7F7F7F;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-dasharray:2,6\"/>\n",
       "<path d=\"M 103.372,46.7374 73.529,35.9943\" style=\"fill:none;fill-rule:evenodd;stroke:#7F7F7F;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-dasharray:2,6\"/>\n",
       "<path d=\"M 64.2866,40.2889 48.0693,61.1976\" style=\"fill:none;fill-rule:evenodd;stroke:#7F7F7F;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-dasharray:2,6\"/>\n",
       "<path d=\"M 38.8268,70.2965 23.9589,80.4015\" style=\"fill:none;fill-rule:evenodd;stroke:#7F7F7F;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 23.9589,80.4015 9.09091,90.5064\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 48.0693,73.9551 62.1776,94.7133\" style=\"fill:none;fill-rule:evenodd;stroke:#7F7F7F;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-dasharray:2,6\"/>\n",
       "<path d=\"M 9.09091,90.5064 32.4417,124.864\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 28.3611,124.085 25.1301,141.026\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 25.1301,141.026 21.899,157.967\" style=\"fill:none;fill-rule:evenodd;stroke:#FF0000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 36.5223,125.642 33.2912,142.583\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 33.2912,142.583 30.0601,159.524\" style=\"fill:none;fill-rule:evenodd;stroke:#FF0000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 32.4417,124.864 47.3097,114.759\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 47.3097,114.759 62.1776,104.654\" style=\"fill:none;fill-rule:evenodd;stroke:#7F7F7F;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<text style=\"font-size:13px;font-style:normal;font-weight:normal;fill-opacity:1;stroke:none;font-family:sans-serif;text-anchor:start;fill:#FF0000\" x=\"127.412\" y=\"163.462\"><tspan>O</tspan></text>\n",
       "<text style=\"font-size:13px;font-style:normal;font-weight:normal;fill-opacity:1;stroke:none;font-family:sans-serif;text-anchor:start;fill:#FF0000\" x=\"171.51\" y=\"106.608\"><tspan>O</tspan></text>\n",
       "<text style=\"font-size:13px;font-style:normal;font-weight:normal;fill-opacity:1;stroke:none;font-family:sans-serif;text-anchor:start;fill:#7F7F7F\" x=\"102.069\" y=\"96.8453\"><tspan>?</tspan></text>\n",
       "<text style=\"font-size:13px;font-style:normal;font-weight:normal;fill-opacity:1;stroke:none;font-family:sans-serif;text-anchor:start;fill:#7F7F7F\" x=\"103.372\" y=\"55.3245\"><tspan>?</tspan></text>\n",
       "<text style=\"font-size:13px;font-style:normal;font-weight:normal;fill-opacity:1;stroke:none;font-family:sans-serif;text-anchor:start;fill:#7F7F7F\" x=\"64.2866\" y=\"41.2543\"><tspan>?</tspan></text>\n",
       "<text style=\"font-size:13px;font-style:normal;font-weight:normal;fill-opacity:1;stroke:none;font-family:sans-serif;text-anchor:start;fill:#7F7F7F\" x=\"38.8268\" y=\"74.0792\"><tspan>?</tspan></text>\n",
       "<text style=\"font-size:13px;font-style:normal;font-weight:normal;fill-opacity:1;stroke:none;font-family:sans-serif;text-anchor:start;fill:#FF0000\" x=\"18.1927\" y=\"172.593\"><tspan>O</tspan></text>\n",
       "<text style=\"font-size:13px;font-style:normal;font-weight:normal;fill-opacity:1;stroke:none;font-family:sans-serif;text-anchor:start;fill:#7F7F7F\" x=\"62.1776\" y=\"108.436\"><tspan>?</tspan></text>\n",
       "</g>\n",
       "<g transform=\"translate(400,0)\"><rect height=\"200\" style=\"opacity:1.0;fill:#FFFFFF;stroke:none\" width=\"200\" x=\"0\" y=\"0\"> </rect>\n",
       "</g></svg>"
      ],
      "text/plain": [
       "<IPython.core.display.SVG object>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from rdkit.Chem import Draw\n",
    "Draw.MolsToGridImage(cores.values())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To use RGroupDecomposition:\n",
    "  \n",
    "  1. construct the class on the core rg = RGroupDecomposition(core)\n",
    "  2. Call rg.Add( mol ) on the molecules.  If this returns -1, the molecule is not\n",
    "     compatible with the core\n",
    "  3. After all molecules are added, call rg.Process() to complete the rgroup\n",
    "     decomposition."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Added 1000\n",
      "Added 2000\n",
      "Added 3000\n",
      "Added 4000\n",
      "Added 2309 to RGroup Decomposition out of 4340\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "RDKit ERROR: [07:31:59] SMILES Parse Error: syntax error for input: 'CANONICAL_SMILES'\n"
     ]
    }
   ],
   "source": [
    "rg = RGroupDecomposition(cores.values())\n",
    "\n",
    "mols = []\n",
    "count = 0\n",
    "maxidx = -1\n",
    "for line in open(\"compounds.txt\"):\n",
    "    sm = line.split()[-1]\n",
    "    m = Chem.MolFromSmiles(sm)\n",
    "    if m:\n",
    "        count += 1\n",
    "        maxidx = max(maxidx,rg.Add(m))\n",
    "        if count % 1000 == 0:\n",
    "            print(\"Added\", count)\n",
    "\n",
    "print (\"Added %s to RGroup Decomposition out of %s\"%(maxidx, count))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rg.Process()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Rendering this many molecules is pretty taxing for the current system, this takes a while.\n",
    "\n",
    "It is useful to disable logging here.  When making RGroup renderings there \n",
    "are a lot of sanitization warnings."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from rdkit import rdBase\n",
    "rdBase.DisableLog(\"rdApp.*\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The RGroupDecomposition code is quite compatiable with the python pandas integration.\n",
    "Calling rg.GetRGroupsAsColumns() can be sent directly into a pandas table.\n",
    "\n",
    "**n.b.** You need to call PandasTools.ChangeMoleculeRendering(frame) to allow the molecules\n",
    "to be rendered properly."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "frame = pd.DataFrame(rg.GetRGroupsAsColumns())\n",
    "PandasTools.ChangeMoleculeRendering(frame)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Just show the first few (for speed and to keep the notebook small)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Core</th>\n",
       "      <th>R1</th>\n",
       "      <th>R2</th>\n",
       "      <th>R3</th>\n",
       "      <th>R4</th>\n",
       "      <th>R5</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td><img src=\"\" alt=\"Mol\"/></td>\n",
       "      <td><img src=\"\" alt=\"Mol\"/></td>\n",
       "      <td><img src=\"\" alt=\"Mol\"/></td>\n",
       "      <td><img src=\"\" alt=\"Mol\"/></td>\n",
       "      <td><img src=\"\" alt=\"Mol\"/></td>\n",
       "      <td><img src=\"\" alt=\"Mol\"/></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td><img src=\"\" alt=\"Mol\"/></td>\n",
       "      <td><img src=\"\" alt=\"Mol\"/></td>\n",
       "      <td><img src=\"\" alt=\"Mol\"/></td>\n",
       "      <td><img src=\"\" alt=\"Mol\"/></td>\n",
       "      <td><img src=\"\" alt=\"Mol\"/></td>\n",
       "      <td><img src=\"\" alt=\"Mol\"/></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td><img src=\"\" alt=\"Mol\"/></td>\n",
       "      <td><img src=\"\" alt=\"Mol\"/></td>\n",
       "      <td><img src=\"\" alt=\"Mol\"/></td>\n",
       "      <td><img src=\"\" alt=\"Mol\"/></td>\n",
       "      <td><img src=\"\" alt=\"Mol\"/></td>\n",
       "      <td><img src=\"\" alt=\"Mol\"/></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td><img src=\"\" alt=\"Mol\"/></td>\n",
       "      <td><img src=\"\" alt=\"Mol\"/></td>\n",
       "      <td><img src=\"\" alt=\"Mol\"/></td>\n",
       "      <td><img src=\"\" alt=\"Mol\"/></td>\n",
       "      <td><img src=\"\" alt=\"Mol\"/></td>\n",
       "      <td><img src=\"\" alt=\"Mol\"/></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td><img src=\"\" alt=\"Mol\"/></td>\n",
       "      <td><img src=\"\" alt=\"Mol\"/></td>\n",
       "      <td><img src=\"\" alt=\"Mol\"/></td>\n",
       "      <td><img src=\"\" alt=\"Mol\"/></td>\n",
       "      <td><img src=\"\" alt=\"Mol\"/></td>\n",
       "      <td><img src=\"\" alt=\"Mol\"/></td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>"
      ],
      "text/plain": [
       "                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    Core                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             R1                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     R2                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             R3                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             R4                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 R5\n",
       "0  <img src=\"\" alt=\"Mol\"/>  <img src=\"\" alt=\"Mol\"/>  <img src=\"\" alt=\"Mol\"/>  <img src=\"\" alt=\"Mol\"/>  <img src=\"\" alt=\"Mol\"/>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          <img src=\"\" alt=\"Mol\"/>\n",
       "1  <img src=\"\" alt=\"Mol\"/>                                                  <img src=\"\" alt=\"Mol\"/>                                                                                                                                                                                                                                                                                  <img src=\"\" alt=\"Mol\"/>                                                  <img src=\"\" alt=\"Mol\"/>                                                  <img src=\"\" alt=\"Mol\"/>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              <img src=\"\" alt=\"Mol\"/>\n",
       "2  <img src=\"\" alt=\"Mol\"/>              <img src=\"\" alt=\"Mol\"/>      <img src=\"\" alt=\"Mol\"/>              <img src=\"\" alt=\"Mol\"/>              <img src=\"\" alt=\"Mol\"/>                                                                                                                                                              <img src=\"\" alt=\"Mol\"/>\n",
       "3  <img src=\"\" alt=\"Mol\"/>                                                      <img src=\"\" alt=\"Mol\"/>                                                                                                                                                                                                                                                                                  <img src=\"\" alt=\"Mol\"/>                                                      <img src=\"\" alt=\"Mol\"/>                                                      <img src=\"\" alt=\"Mol\"/>                                                                                                                                                              <img src=\"\" alt=\"Mol\"/>\n",
       "4  <img src=\"\" alt=\"Mol\"/>                                                      <img src=\"\" alt=\"Mol\"/>                                                                                                                                                                                                                                                                                  <img src=\"\" alt=\"Mol\"/>                                                      <img src=\"\" alt=\"Mol\"/>                                                      <img src=\"\" alt=\"Mol\"/>  <img src=\"\" alt=\"Mol\"/>"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f2 = pd.DataFrame(frame.head())\n",
    "PandasTools.ChangeMoleculeRendering(f2)\n",
    "f2"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
